#!/bin/bash
    DEBPATH="${1}"
    DEBPATH="${DEBPATH#file://}"
WORKDIR=`dirname $DEBPATH`
package_name=`dpkg-deb -f $DEBPATH  Package`

if [[ ! $package_name =~ ^store\.spark-app\.appwrapper\. ]]; then
    notify-send "错误：暂不支持非套娃包获取icon" -i /opt/apps/cn.flamescion.taowa-tools/entries/icons/hicolor/512x512/apps/cn.flamescion.taowa-tools.png
    exit
fi


package_name=$(echo "$package_name" | sed 's/store\.spark-app\.appwrapper\.//')

cd $WORKDIR
mkdir ${package_name}-icon
cd ${package_name}-icon
# 下载deb包
apt download $package_name

# 检查是否成功下载
if [ $? -eq 0 ]; then
    echo "成功下载deb包"
else
    echo "无法下载deb包"
    exit 1
fi

# 获取下载的deb包文件名
package_file=$(ls | grep "$package_name")

# 解压缩deb包
mkdir extracted-package
dpkg -X "$package_file" extracted-package


# 复制/usr/share/icons中的内容到当前目录
cd ..

cp -R ${package_name}-icon/extracted-package/usr/share/icons .
cp -R ${package_name}-icon/extracted-package/usr/share/pixmaps/ .
rm -rf ${package_name}-icon

notify-send "处理完成" -i /opt/apps/cn.flamescion.taowa-tools/entries/icons/hicolor/512x512/apps/cn.flamescion.taowa-tools.png
